<?php

/*
 * This file is part of the symfony package.
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * sfWidgetFormInputFileBts represents an upload HTML input tag.
 *
 * @package    symfony
 * @subpackage widget
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
 * @version    SVN: $Id$
 */
class sfWidgetFormPlainText extends sfWidgetForm
{
  /**
   * @param array $options     An array of options
   * @param array $attributes  An array of default HTML attributes
   *
   * @see sfWidgetFormInput
   */
  protected function configure($options = array(), $attributes = array())
  {
    $this->addOption('model');
    $this->addOption('disallowUpdate');
  }
  
  
  public function render($name, $value = null, $attributes = array(), $errors = array())
 {
    $text = $value;
    
    if ( $this->getOption('model') ){
        $text = Doctrine_Core::getTable($this->getOption('model'))->find($value);
    }
    
    $input = '<div>' . $text . '<br/><span style="display:none">' . $this->renderTag('input', array_merge(array('type' => 'text', 'name' => $name, 'value' => $value), $attributes)) .  '</span>';

    if ( is_null($this->getOption('disallowUpdate')) ){
        $input .= '<a href="#" class="showhiddenfield">Modifier</a></div>
								    <script>
								        $(document).ready(function(e){
								            $(".showhiddenfield").click(function(e){
								                e.preventDefault();
								                $(this).prev().show();
								            });
								        });
								    </script>';
    }
    
    
    
    return  $input;
    
 }
  
  
}
